package telnetserver;

public class Login {
    private Telnet telnet;
    private Menu menu;
    
    public Login(Telnet t, Menu m) {
        menu = m;
        telnet = t;
    }
    
    public void addUser(User u) {
        u.clear();
        u.prepare(1, 27, 1, "___  __            __  ___");
        u.prepare(27, 2, " |  | _| |   |\\ | | _|  |");
        u.prepare(27, 3, " |  |__  |__ | \\| |__   |");
        
        u.prepare(34, 6, " _____NICK____");
        u.prepare(34, 7, "|             |");
        u.prepare(34, 8, "|             |");
        u.prepare(34, 9, "|_____________|");
        u.prepare(36, 8, "");
        u.send();
    }
    
    public void read(User u, String s) {
        if (s.trim().length() > 0) {
            if (!telnet.userExists(s)) {
                u.setNick(s);
                telnet.changeMode(u, menu);
            } else {
                u.prepare(25, 12, "Nickname " + s + " is already in use.");
                u.prepare(35, 8, "             ");
                u.prepare(35, 8, "");
                u.send();
            }
        }
    }
}


